// 2025/11/17
// 单词拆分

class Solution {
public:
    bool wordBreak(string s, vector<string>& wordDict) {
        int n = s.size();
        vector<bool> dp(n + 1, false);
        dp[0] = true;
        for(int i = 1; i <= n; i++)
        {
            for(auto &word : wordDict)
            {
                int len = word.size();
                if(len <= i && dp[i - len])
                {
                    dp[i] = s.substr(i - len, len) == word;
                    if(dp[i]) break;
                }
            }
        }
        return dp[n];
    }
};